# -*- coding: utf8 -*-

import os
import sys
reload(sys) 
sys.setdefaultencoding('utf8')
import caller
import webkit
import webpage
import webelement
import time
import caller

gconfig = caller.GlobalConfig()
gconfig.init("10.58.222.103:2181")

wk = webkit.WebKit("wshpc")
page = wk.getWebPage("http://pachong.org/", 30000, 40000)

if page is None:
    _exit(0)

if page.waitForCssSelector(".tb > tbody> tr", 100):
    elements = page.getElementsByCssSelector(".tb > tbody> tr")
    for element in elements:
        contents = element.getChildsByCssSelector("td")
        if len(contents) == 7:
            anonymousType = contents[4].getText()
            status = contents[5].getText()
            if anonymousType == "anonymous" and not status.find("空闲") == -1:
                host = contents[1].getText()
                port = contents[2].getText()
                print host + " : " + port + " : " + status

page.destroy()
wk.release()

